var Bmob = require('../../utils/bmob.js');
var common = require('../../utils/common.js');
var app = getApp()
Page({
    data: {
        userInfo: {},
        verifySmsCode: '',
        phone: '',
    },
    onLoad: function () {
        var that = this
        //调用应用实例的方法获取全局数据
        app.getUserInfo(function (userInfo) {
            console.log(userInfo)
            //更新数据
            that.setData({
                userInfo: userInfo
            })
        })
    },
    sendSms: function (event) {
        var that = this
        var river_name = event.detail.value.river_name;
        var alarm_info = event.detail.value.alarm_info;
        var email = event.detail.value.email;
        if (river_name != "" && alarm_info != "" && email!= "") {
  wx.request({
    url: 'https://hezhang1.luckyye.top/admin/weixin/email',
    data: {
      river_id: 'szzjgysriver01',
      town_name: '杨舍镇',
      manager_name: '杨舍镇河道负责人老王',
      river_name: river_name,
      alarm_info: alarm_info,
      email: email
    },
    // 请求头
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: "POST",
    success: function (res) {
      console.log(res.data);
      if (res.data['res'] == 1) {
        common.showTip('成功发送！');
      }else {
        common.showTip('发送失败！');
      }
    }
  })
        }else {
          wx.showLoading({
            title: '邮件信息错误！',
          });
          setTimeout(function() {
            wx.hideLoading();
          },1500)
        }


    },
    verifySmsCode: function (event) {
        var phone = this.data.phone;
        var verifyCode = event.detail.value.verifyCode;
        if (!phone) {
            common.showTip('请发送短信后再验证');
            return false;
        } else if (!verifyCode) {
            common.showTip('请输入验证码');
            return false;
        }

        Bmob.Sms.verifySmsCode(phone, verifyCode).then(function (obj) {
            common.showTip('验证成功' + "smsId:" + obj.msg);
            that.setData({
                verifySmsCode: "验证成功"
            })
        }, function (err) {
            common.showTip('验证失败' + err);
            that.setData({
                verifySmsCode: "验证失败"
            })
        });
    }
})